package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    Page<DishVO> page(String name, Long categoryId, Integer status);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void save(Dish dish);

    DishVO getByIdWithFlavors(Long id);

    void delete(List<Long> ids);

    List<Dish> getByIds(List<Long> ids);
    @Select("select * from dish where status = 1 and category_id = #{categoryId}")
    List<Dish> listByCategoryId(Long categoryId);

    List<Dish> getBySetmealId(Long id);
}
